home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / rastan.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  18KB  |  793 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13. void rastan_vh_stop (void);
  14.  
  15. size_t rastan_videoram_size;
  16. unsigned char *rastan_videoram1;
  17. unsigned char *rastan_videoram3;
  18. unsigned char *rastan_spriteram;
  19. unsigned char *rastan_scrollx;
  20. unsigned char *rastan_scrolly;
  21.  
  22. static unsigned char *rastan_dirty1;
  23. static unsigned char *rastan_dirty3;
  24.  
  25. static unsigned char spritepalettebank;
  26. static int flipscreen;
  27.  
  28. static struct osd_bitmap *tmpbitmap1;
  29. static struct osd_bitmap *tmpbitmap3;
  30.  
  31.  
  32.  
  33. int rastan_vh_start (void)
  34. {
  35.     /* Allocate a video RAM */
  36.     rastan_dirty1 = malloc ( rastan_videoram_size/4);
  37.     if (!rastan_dirty1)
  38.     {
  39.         rastan_vh_stop();
  40.         return 1;
  41.     }
  42.     memset(rastan_dirty1,1,rastan_videoram_size / 4);
  43.  
  44.     rastan_dirty3 = malloc ( rastan_videoram_size/4);
  45.     if (!rastan_dirty3)
  46.     {
  47.         rastan_vh_stop();
  48.         return 1;
  49.     }
  50.     memset(rastan_dirty3,1,rastan_videoram_size / 4);
  51.  
  52.     /* Allocate temporary bitmaps */
  53.      if ((tmpbitmap1 = osd_create_bitmap(512,512)) == 0)
  54.     {
  55.         rastan_vh_stop ();
  56.         return 1;
  57.     }
  58.     if ((tmpbitmap3 = osd_create_bitmap(512,512)) == 0)
  59.     {
  60.         rastan_vh_stop ();
  61.         return 1;
  62.     }
  63.  
  64.     flipscreen = 0; /*maybe not needed*/
  65.  
  66.     return 0;
  67. }
  68.  
  69.  
  70.  
  71. void rastan_vh_stop (void)
  72. {
  73.     /* Free temporary bitmaps */
  74.     if (tmpbitmap3)
  75.         osd_free_bitmap (tmpbitmap3);
  76.     tmpbitmap3 = 0;
  77.     if (tmpbitmap1)
  78.         osd_free_bitmap (tmpbitmap1);
  79.     tmpbitmap1 = 0;
  80.  
  81.     /* Free video RAM */
  82.     if (rastan_dirty1)
  83.             free (rastan_dirty1);
  84.     if (rastan_dirty3)
  85.             free (rastan_dirty3);
  86.     rastan_dirty1 = rastan_dirty3 = 0;
  87. }
  88.  
  89.  
  90.  
  91. /*
  92.  *   scroll write handlers
  93.  */
  94.  
  95. WRITE_HANDLER( rastan_scrollY_w )
  96. {
  97.     COMBINE_WORD_MEM (&rastan_scrolly[offset], data);
  98. }
  99.  
  100. WRITE_HANDLER( rastan_scrollX_w )
  101. {
  102.     COMBINE_WORD_MEM (&rastan_scrollx[offset], data);
  103. }
  104.  
  105.  
  106.  
  107. WRITE_HANDLER( rastan_videoram1_w )
  108. {
  109.     int oldword = READ_WORD(&rastan_videoram1[offset]);
  110.     int newword = COMBINE_WORD(oldword,data);
  111.  
  112.  
  113.     if (oldword != newword)
  114.     {
  115.         WRITE_WORD(&rastan_videoram1[offset],newword);
  116.         rastan_dirty1[offset / 4] = 1;
  117.     }
  118. }
  119. READ_HANDLER( rastan_videoram1_r )
  120. {
  121.    return READ_WORD (&rastan_videoram1[offset]);
  122. }
  123.  
  124. WRITE_HANDLER( rastan_videoram3_w )
  125. {
  126.     int oldword = READ_WORD(&rastan_videoram3[offset]);
  127.     int newword = COMBINE_WORD(oldword,data);
  128.  
  129.  
  130.     if (oldword != newword)
  131.     {
  132.         WRITE_WORD(&rastan_videoram3[offset],newword);
  133.         rastan_dirty3[offset / 4] = 1;
  134.     }
  135. }
  136. READ_HANDLER( rastan_videoram3_r )
  137. {
  138.    return READ_WORD (&rastan_videoram3[offset]);
  139. }
  140.  
  141.  
  142.  
  143. WRITE_HANDLER( rastan_videocontrol_w )
  144. {
  145.     if (offset == 0)
  146.     {
  147.         /* bits 2 and 3 are the coin counters */
  148.  
  149.         /* bits 5-7 look like the sprite palette bank */
  150.         spritepalettebank = (data & 0xe0) >> 5;
  151.  
  152.         /* other bits unknown */
  153.     }
  154. }
  155.  
  156. WRITE_HANDLER( rastan_flipscreen_w )
  157. {
  158.     if (offset == 0)
  159.     {
  160.         /* flipscreen when bit 0 set */
  161.         if (flipscreen != (data & 1) )
  162.         {
  163.             flipscreen = data & 1;
  164.             memset(rastan_dirty1,1,rastan_videoram_size / 4);
  165.             memset(rastan_dirty3,1,rastan_videoram_size / 4);
  166.         }
  167.     }
  168. }
  169.  
  170.  
  171. /***************************************************************************
  172.  
  173.   Draw the game screen in the given osd_bitmap.
  174.   Do NOT call osd_update_display() from this function, it will be called by
  175.   the main emulation engine.
  176.  
  177. ***************************************************************************/
  178. void rastan_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  179. {
  180.     int offs;
  181.     int scrollx,scrolly;
  182.  
  183.  
  184. palette_init_used_colors();
  185.  
  186. {
  187.     int color,code,i;
  188.     int colmask[128];
  189.     int pal_base;
  190.  
  191.  
  192.     pal_base = 0;
  193.  
  194.     for (color = 0;color < 128;color++) colmask[color] = 0;
  195.  
  196.     for (offs = rastan_videoram_size - 4;offs >= 0;offs -= 4)
  197.     {
  198.         code = READ_WORD(&rastan_videoram1[offs + 2]) & 0x3fff;
  199.         color = READ_WORD(&rastan_videoram1[offs]) & 0x7f;
  200.  
  201.         colmask[color] |= Machine->gfx[0]->pen_usage[code];
  202.     }
  203.  
  204.     for (offs = rastan_videoram_size - 4;offs >= 0;offs -= 4)
  205.     {
  206.         code = READ_WORD(&rastan_videoram3[offs + 2]) & 0x3fff;
  207.         color = READ_WORD(&rastan_videoram3[offs]) & 0x7f;
  208.  
  209.         colmask[color] |= Machine->gfx[0]->pen_usage[code];
  210.     }
  211.  
  212.     for (offs = 0x800-8; offs >= 0; offs -= 8)
  213.     {
  214.         code = READ_WORD (&rastan_spriteram[offs+4]) & 0x0fff;
  215.  
  216.         if (code)
  217.         {
  218.             int data1;
  219.  
  220.             data1 = READ_WORD (&rastan_spriteram[offs]);
  221.  
  222.             color = (data1 & 0x0f) + 0x10 * spritepalettebank;
  223.             colmask[color] |= Machine->gfx[1]->pen_usage[code];
  224.         }
  225.     }
  226.  
  227.     for (color = 0;color < 128;color++)
  228.     {
  229.         if (colmask[color] & (1 << 0))
  230.             palette_used_colors[pal_base + 16 * color] = PALETTE_COLOR_TRANSPARENT;
  231.         for (i = 1;i < 16;i++)
  232.         {
  233.             if (colmask[color] & (1 << i))
  234.                 palette_used_colors[pal_base + 16 * color + i] = PALETTE_COLOR_USED;
  235.         }
  236.     }
  237.  
  238.  
  239.     if (palette_recalc())
  240.     {
  241.         memset(rastan_dirty1,1,rastan_videoram_size / 4);
  242.         memset(rastan_dirty3,1,rastan_videoram_size / 4);
  243.     }
  244. }
  245.  
  246.  
  247.     for (offs = rastan_videoram_size - 4;offs >= 0;offs -= 4)
  248.     {
  249.         if (rastan_dirty1[offs/4])
  250.         {
  251.             int sx,sy;
  252.             int data1,data2;
  253.             int flipx,flipy;
  254.  
  255.  
  256.             rastan_dirty1[offs/4] = 0;
  257.  
  258.             data1 = READ_WORD(&rastan_videoram1[offs]);
  259.             data2 = READ_WORD(&rastan_videoram1[offs + 2]);
  260.  
  261.             sx = (offs/4) % 64;
  262.             sy = (offs/4) / 64;
  263.  
  264.             flipx = data1 & 0x4000;
  265.             flipy = data1 & 0x8000;
  266.  
  267.             if (flipscreen)
  268.             {
  269.                 flipx = !flipx;
  270.                 flipy = !flipy;
  271.                 sx = 63 - sx;
  272.                 sy = 63 - sy;
  273.             }
  274.  
  275.             drawgfx(tmpbitmap1, Machine->gfx[0],
  276.                     data2 & 0x3fff,
  277.                     data1 & 0x7f,
  278.                     flipx, flipy,
  279.                     8*sx,8*sy,
  280.                     0,TRANSPARENCY_NONE,0);
  281.         }
  282.     }
  283.  
  284.     for (offs = rastan_videoram_size - 4;offs >= 0;offs -= 4)
  285.     {
  286.         if (rastan_dirty3[offs/4])
  287.         {
  288.             int sx,sy;
  289.             int data1,data2;
  290.             int flipx,flipy;
  291.  
  292.  
  293.             rastan_dirty3[offs/4] = 0;
  294.  
  295.             data1 = READ_WORD(&rastan_videoram3[offs]);
  296.             data2 = READ_WORD(&rastan_videoram3[offs + 2]);
  297.  
  298.             sx = (offs/4) % 64;
  299.             sy = (offs/4) / 64;
  300.  
  301.             flipx = data1 & 0x4000;
  302.             flipy = data1 & 0x8000;
  303.  
  304.             if (flipscreen)
  305.             {
  306.                 flipx = !flipx;
  307.                 flipy = !flipy;
  308.                 sx = 63 - sx;
  309.                 sy = 63 - sy;
  310.             }
  311.  
  312.             drawgfx(tmpbitmap3, Machine->gfx[0],
  313.                     data2 & 0x3fff,
  314.                     data1 & 0x7f,
  315.                     flipx, flipy,
  316.                     8*sx,8*sy,
  317.                     0,TRANSPARENCY_NONE,0);
  318.         }
  319.     }
  320.  
  321.     scrollx = READ_WORD(&rastan_scrollx[0]) - 16;
  322.     scrolly = READ_WORD(&rastan_scrolly[0]);
  323.     if (flipscreen)
  324.     {
  325.         scrollx = 320-scrollx;
  326.         scrolly = 240-scrolly+16;
  327.     }
  328.     copyscrollbitmap(bitmap,tmpbitmap1,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  329.  
  330.     scrollx = READ_WORD(&rastan_scrollx[2]) - 16;
  331.     scrolly = READ_WORD(&rastan_scrolly[2]);
  332.     if (flipscreen)
  333.     {
  334.         scrollx = 320-scrollx;
  335.         scrolly = 240-scrolly+16;
  336.     }
  337.     copyscrollbitmap(bitmap,tmpbitmap3,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_PEN,palette_transparent_pen);
  338.  
  339.  
  340.     /* Draw the sprites. 256 sprites in total */
  341.     for (offs = 0x800-8; offs >= 0; offs -= 8)
  342.     {
  343.         int num = READ_WORD (&rastan_spriteram[offs+4]);
  344.  
  345.         if (num)
  346.         {
  347.             int sx,sy,col,data1;
  348.             int flipx,flipy;
  349.  
  350.             sx = READ_WORD(&rastan_spriteram[offs+6]) & 0x1ff;
  351.             if (sx > 400) sx = sx - 512;
  352.             sy = READ_WORD(&rastan_spriteram[offs+2]) & 0x1ff;
  353.             if (sy > 400) sy = sy - 512;
  354.  
  355.             data1 = READ_WORD (&rastan_spriteram[offs]);
  356.  
  357.             col = (data1 & 0x0f) + 0x10 * spritepalettebank;
  358.  
  359.             flipx = data1 & 0x4000;
  360.             flipy = data1 & 0x8000;
  361.  
  362.             if (flipscreen)
  363.             {
  364.                 flipx = !flipx;
  365.                 flipy = !flipy;
  366.                 sx = 320 - sx - 16;
  367.                 sy = 240 - sy;
  368.             }
  369.  
  370.             drawgfx(bitmap,Machine->gfx[1],
  371.                     num,
  372.                     col,
  373.                     flipx, flipy,
  374.                     sx,sy,
  375.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  376.         }
  377.     }
  378. }
  379.  
  380. void rainbow_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  381. {
  382.     int offs;
  383.     int scrollx,scrolly;
  384.  
  385.  
  386. palette_init_used_colors();
  387.  
  388. /* TODO: we are using the same table for background and foreground tiles, but this */
  389. /* causes the sky to be black instead of blue. */
  390. {
  391.     int color,code,i;
  392.     int colmask[128];
  393.     int pal_base;
  394.  
  395.  
  396.     pal_base = 0;
  397.  
  398.     for (color = 0;color < 128;color++)
  399.     {
  400.         colmask[color] = 0;
  401.     }
  402.  
  403.     for (offs = rastan_videoram_size - 4;offs >= 0;offs -= 4)
  404.     {
  405.         code = READ_WORD(&rastan_videoram1[offs + 2]) & 0x3FFF;
  406.         color = READ_WORD(&rastan_videoram1[offs]) & 0x7f;
  407.  
  408.         colmask[color] |= Machine->gfx[0]->pen_usage[code];
  409.     }
  410.  
  411.     for (offs = rastan_videoram_size - 4;offs >= 0;offs -= 4)
  412.     {
  413.         code = READ_WORD(&rastan_videoram3[offs + 2]) & 0x3fff;
  414.         color = READ_WORD(&rastan_videoram3[offs]) & 0x7f;
  415.  
  416.         colmask[color] |= Machine->gfx[0]->pen_usage[code];
  417.     }
  418.  
  419.     for (offs = 0x800-8; offs >= 0; offs -= 8)
  420.     {
  421.         code = READ_WORD (&rastan_spriteram[offs+4]);
  422.  
  423.         if (code)
  424.         {
  425.             int data1;
  426.  
  427.             data1 = READ_WORD (&rastan_spriteram[offs]);
  428.  
  429.             color = (data1 + 0x10) & 0x7f;
  430.  
  431.             if(code < 4096)
  432.                 colmask[color] |= Machine->gfx[1]->pen_usage[code];
  433.             else
  434.                 colmask[color] |= Machine->gfx[2]->pen_usage[code-4096];
  435.         }
  436.     }
  437.  
  438.     for (color = 0;color < 128;color++)
  439.     {
  440.         if (colmask[color] & (1 << 0))
  441.             palette_used_colors[pal_base + 16 * color] = PALETTE_COLOR_USED;
  442.  
  443.         for (i = 1;i < 16;i++)
  444.         {
  445.             if (colmask[color] & (1 << i))
  446.                 palette_used_colors[pal_base + 16 * color + i] = PALETTE_COLOR_USED;
  447.         }
  448.     }
  449.  
  450.     /* Make one transparent colour */
  451.  
  452.     palette_used_colors[pal_base] = PALETTE_COLOR_TRANSPARENT;
  453.  
  454.     if (palette_recalc())
  455.     {
  456.         memset(rastan_dirty1,1,rastan_videoram_size / 4);
  457.         memset(rastan_dirty3,1,rastan_videoram_size / 4);
  458.     }
  459. }
  460.  
  461.  
  462.     for (offs = rastan_videoram_size - 4;offs >= 0;offs -= 4)
  463.     {
  464.         if (rastan_dirty1[offs/4])
  465.         {
  466.             int sx,sy;
  467.             int data1,data2;
  468.             int flipx,flipy;
  469.  
  470.  
  471.             rastan_dirty1[offs/4] = 0;
  472.  
  473.             data1 = READ_WORD(&rastan_videoram1[offs]);
  474.             data2 = READ_WORD(&rastan_videoram1[offs + 2]);
  475.  
  476.             sx = (offs/4) % 64;
  477.             sy = (offs/4) / 64;
  478.  
  479.             flipx = data1 & 0x4000;
  480.             flipy = data1 & 0x8000;
  481.  
  482.             if (flipscreen)
  483.             {
  484.                 flipx = !flipx;
  485.                 flipy = !flipy;
  486.                 sx = 63 - sx;
  487.                 sy = 63 - sy;
  488.             }
  489.  
  490.             drawgfx(tmpbitmap1, Machine->gfx[0],
  491.                     data2 & 0x3fff,
  492.                     data1 & 0x7f,
  493.                     flipx, flipy,
  494.                     8*sx,8*sy,
  495.                     0,TRANSPARENCY_NONE,0);
  496.         }
  497.     }
  498.  
  499.     for (offs = rastan_videoram_size - 4;offs >= 0;offs -= 4)
  500.     {
  501.         if (rastan_dirty3[offs/4])
  502.         {
  503.             int sx,sy;
  504.             int data1,data2;
  505.             int flipx,flipy;
  506.  
  507.  
  508.             rastan_dirty3[offs/4] = 0;
  509.  
  510.             data1 = READ_WORD(&rastan_videoram3[offs]);
  511.             data2 = READ_WORD(&rastan_videoram3[offs + 2]);
  512.  
  513.             sx = (offs/4) % 64;
  514.             sy = (offs/4) / 64;
  515.  
  516.             flipx = data1 & 0x4000;
  517.             flipy = data1 & 0x8000;
  518.  
  519.             if (flipscreen)
  520.             {
  521.                 flipx = !flipx;
  522.                 flipy = !flipy;
  523.                 sx = 63 - sx;
  524.                 sy = 63 - sy;
  525.             }
  526.             /* Colour as Transparent */
  527.  
  528.             drawgfx(tmpbitmap3, Machine->gfx[0],
  529.                     0,
  530.                     0,
  531.                     flipx, flipy,
  532.                     8*sx,8*sy,
  533.                     0,TRANSPARENCY_NONE,0);
  534.  
  535.             /* Draw over with correct Transparency */
  536.  
  537.             drawgfx(tmpbitmap3, Machine->gfx[0],
  538.                     data2 & 0x3fff,
  539.                     data1 & 0x7f,
  540.                     flipx, flipy,
  541.                     8*sx,8*sy,
  542.                     0,TRANSPARENCY_PEN,0);
  543.         }
  544.     }
  545.  
  546.     scrollx = READ_WORD(&rastan_scrollx[0]) - 16;
  547.     scrolly = READ_WORD(&rastan_scrolly[0]);
  548.     if (flipscreen)
  549.     {
  550.         scrollx = 320-scrollx;
  551.         scrolly = 240-scrolly+16;
  552.     }
  553.     copyscrollbitmap(bitmap,tmpbitmap1,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  554.  
  555.     /* Draw the sprites. 256 sprites in total */
  556.     for (offs = 0x800-8; offs >= 0; offs -= 8)
  557.     {
  558.         int num = READ_WORD (&rastan_spriteram[offs+4]);
  559.  
  560.         if (num)
  561.         {
  562.             int sx,sy,col,data1;
  563.             int flipx,flipy;
  564.  
  565.  
  566.             sx = READ_WORD(&rastan_spriteram[offs+6]) & 0x1ff;
  567.             if (sx > 400) sx = sx - 512;
  568.             sy = READ_WORD(&rastan_spriteram[offs+2]) & 0x1ff;
  569.             if (sy > 400) sy = sy - 512;
  570.  
  571.             data1 = READ_WORD (&rastan_spriteram[offs]);
  572.  
  573.             col = (data1 + 0x10) & 0x7f;
  574.  
  575.             flipx = data1 & 0x4000;
  576.             flipy = data1 & 0x8000;
  577.  
  578.             if (flipscreen)
  579.             {
  580.                 flipx = !flipx;
  581.                 flipy = !flipy;
  582.                 sx = 320 - sx - 16;
  583.                 sy = 240 - sy;
  584.             }
  585.  
  586.  
  587.             if(num < 4096)
  588.                 drawgfx(bitmap,Machine->gfx[1],
  589.                         num,
  590.                         col,
  591.                         flipx, flipy,
  592.                         sx,sy,
  593.                         &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  594.             else
  595.                 drawgfx(bitmap,Machine->gfx[2],
  596.                         num-4096,
  597.                         col,
  598.                         flipx, flipy,
  599.                         sx,sy,
  600.                         &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  601.         }
  602.     }
  603.  
  604.     scrollx = READ_WORD(&rastan_scrollx[2]) - 16;
  605.     scrolly = READ_WORD(&rastan_scrolly[2]);
  606.     if (flipscreen)
  607.     {
  608.         scrollx = 320-scrollx;
  609.         scrolly = 240-scrolly+16;
  610.     }
  611.     copyscrollbitmap(bitmap,tmpbitmap3,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_PEN,palette_transparent_pen);
  612.  
  613.  
  614. }
  615.  
  616.  
  617. /* Jumping uses different sprite controller   */
  618. /* than rainbow island. - values are remapped */
  619. /* at address 0x2EA in the code. Apart from   */
  620. /* physical layout, the main change is that   */
  621. /* the Y settings are active low              */
  622.  
  623. void jumping_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  624. {
  625.     int offs;
  626.     int scrollx,scrolly;
  627.  
  628.     palette_init_used_colors();
  629.  
  630.     /* TODO: we are using the same table for background and foreground tiles, but this */
  631.     /* causes the sky to be black instead of blue. */
  632.     {
  633.         int color,code,i;
  634.         int colmask[128];
  635.         int pal_base;
  636.  
  637.         pal_base = 0;
  638.  
  639.         for (color = 0;color < 128;color++) colmask[color] = 0;
  640.  
  641.         for (offs = rastan_videoram_size - 4;offs >= 0;offs -= 4)
  642.         {
  643.             code = READ_WORD(&rastan_videoram1[offs + 2]) & 0x3FFF;
  644.             color = READ_WORD(&rastan_videoram1[offs]) & 0x7f;
  645.  
  646.             colmask[color] |= Machine->gfx[0]->pen_usage[code];
  647.         }
  648.  
  649.         for (offs = 0x800-8; offs >= 0; offs -= 8)
  650.         {
  651.             code = READ_WORD (&rastan_spriteram[offs]);
  652.  
  653.             if (code < Machine->gfx[1]->total_elements)
  654.             {
  655.                 int data1;
  656.  
  657.                 data1 = READ_WORD (&rastan_spriteram[offs+8]);
  658.  
  659.                 color = (data1 + 0x10) & 0x7f;
  660.                 colmask[color] |= Machine->gfx[1]->pen_usage[code];
  661.             }
  662.         }
  663.  
  664.         for (offs = rastan_videoram_size - 4;offs >= 0;offs -= 4)
  665.         {
  666.             code = READ_WORD(&rastan_videoram3[offs + 2]) & 0x3FFF;
  667.             color = READ_WORD(&rastan_videoram3[offs]) & 0x7f;
  668.  
  669.             colmask[color] |= Machine->gfx[0]->pen_usage[code];
  670.         }
  671.  
  672.  
  673.         for (color = 0;color < 128;color++)
  674.         {
  675.             if (colmask[color] & (1 << 15))
  676.                 palette_used_colors[pal_base + 16 * color + 15] = PALETTE_COLOR_USED;
  677.  
  678.             for (i = 0;i < 15;i++)
  679.             {
  680.                 if (colmask[color] & (1 << i))
  681.                     palette_used_colors[pal_base + 16 * color + i] = PALETTE_COLOR_USED;
  682.             }
  683.         }
  684.  
  685.         /* Make one transparent colour */
  686.  
  687.         palette_used_colors[pal_base + 15] = PALETTE_COLOR_TRANSPARENT;
  688.  
  689.         if (palette_recalc())
  690.         {
  691.             memset(rastan_dirty1,1,rastan_videoram_size / 4);
  692.             memset(rastan_dirty3,1,rastan_videoram_size / 4);
  693.         }
  694.  
  695.     }
  696.  
  697.     for (offs = rastan_videoram_size - 4;offs >= 0;offs -= 4)
  698.     {
  699.         if (rastan_dirty1[offs/4])
  700.         {
  701.             int sx,sy;
  702.             int data1,data2;
  703.  
  704.             rastan_dirty1[offs/4] = 0;
  705.  
  706.             data1 = READ_WORD(&rastan_videoram1[offs]);
  707.             data2 = READ_WORD(&rastan_videoram1[offs + 2]);
  708.  
  709.             sx = (offs/4) % 64;
  710.             sy = (offs/4) / 64;
  711.  
  712.             drawgfx(tmpbitmap1, Machine->gfx[0],
  713.                     data2,
  714.                     data1 & 0x7f,
  715.                     data1 & 0x4000, data1 & 0x8000,
  716.                     8*sx,8*sy,
  717.                     0,TRANSPARENCY_NONE,0);
  718.         }
  719.     }
  720.  
  721.     for (offs = rastan_videoram_size - 4;offs >= 0;offs -= 4)
  722.     {
  723.         if (rastan_dirty3[offs/4])
  724.         {
  725.             int sx,sy;
  726.             int data1,data2;
  727.  
  728.  
  729.             rastan_dirty3[offs/4] = 0;
  730.  
  731.             data1 = READ_WORD(&rastan_videoram3[offs]);
  732.             data2 = READ_WORD(&rastan_videoram3[offs + 2]);
  733.  
  734.             sx = (offs/4) % 64;
  735.             sy = (offs/4) / 64;
  736.  
  737.             /* Colour as Transparent */
  738.  
  739.             drawgfx(tmpbitmap3, Machine->gfx[0],
  740.                     0,
  741.                     0,
  742.                     0, 0,
  743.                     8*sx,8*sy,
  744.                     0,TRANSPARENCY_NONE,0);
  745.  
  746.             /* Draw over with correct Transparency */
  747.  
  748.             drawgfx(tmpbitmap3, Machine->gfx[0],
  749.                     data2,
  750.                     data1 & 0x7f,
  751.                     data1 & 0x4000, data1 & 0x8000,
  752.                     8*sx,8*sy,
  753.                     0,TRANSPARENCY_PEN,15);
  754.         }
  755.     }
  756.  
  757.     scrollx = READ_WORD(&rastan_scrollx[0]) - 16;
  758.     scrolly = -READ_WORD(&rastan_scrolly[0]);
  759.     copyscrollbitmap(bitmap,tmpbitmap1,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  760.  
  761.     /* Draw the sprites. 128 sprites in total */
  762.  
  763.     for (offs = 0x07F0; offs >= 0; offs -= 16)
  764.     {
  765.         int num = READ_WORD (&rastan_spriteram[offs]);
  766.  
  767.         if (num)
  768.         {
  769.             int  sx,col,data1;
  770.             int sy;
  771.  
  772.             sy = ((READ_WORD(&rastan_spriteram[offs+2]) - 0xFFF1) ^ 0xFFFF) & 0x1FF;
  773.               if (sy > 400) sy = sy - 512;
  774.             sx = (READ_WORD(&rastan_spriteram[offs+4]) - 0x38) & 0x1ff;
  775.             if (sx > 400) sx = sx - 512;
  776.  
  777.             data1 = READ_WORD(&rastan_spriteram[offs+6]);
  778.             col   = (READ_WORD(&rastan_spriteram[offs+8]) + 0x10) & 0x7F;
  779.  
  780.             drawgfx(bitmap,Machine->gfx[1],
  781.                     num,
  782.                     col,
  783.                     data1 & 0x40, data1 & 0x80,
  784.                     sx,sy+1,
  785.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,15);
  786.         }
  787.     }
  788.  
  789.     scrollx = - 16;
  790.     scrolly = 0;
  791.       copyscrollbitmap(bitmap,tmpbitmap3,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_PEN,palette_transparent_pen);
  792. }
  793.